package user_tenant_rel_impl

import (
	"context"
	"nexus/internal/svc"
	"nexus/internal/types"
	"nexus/model"

	"gorm.io/gorm"
)

type UserTenantRelReferenceImpl struct {
	svc *svc.ServiceContext
}

func NewUserReferenceImpl(svc *svc.ServiceContext) UserTenantRelReference {
	return &UserTenantRelReferenceImpl{
		svc: svc,
	}
}

// 用户绑定租户
func (u *UserTenantRelReferenceImpl) UserBindTenant(ctx context.Context, req *types.UserBindTenantReq) error {
	// 构建用户租户关系
	utr := &model.UserTenantRel{
		UserID:   req.UserID,
		TenantID: req.TenantID,
	}

	// 保存用户租户关系
	// 调用model层创建用户租户关系
	return model.NewUserTenantRelClient((*gorm.DB)(u.svc.NexusDB)).Create(utr)
}
